<?php

namespace App\Http\Controllers\Api\V1\Requests;

class CaptchaRequest extends FormRequest
{
    public function rules(): array
    {
	    $type = request('type');

	    $rules = [
		    'type' => 'required|string',
	    ];

	    if ($type == 'register_account') {
	    	$rules['phone'] = 'required|phone:CN,mobile|unique:users';
	    } elseif ($type == 'reset_password'
		    or $type == 'login_account') {
		    $rules['phone'] = 'required|phone:CN,mobile';
	    } elseif ($type == 'set_pay_code') {
	    } else {
		    fail('参数错误');
	    }

        return $rules;
    }

    public function attributes(): array
    {
	    return [
	    	'phone' => '手机号码',
		    'type' => '图片验证码类型',
	    ];
    }
}
